import {
  defineConfig
} from "vite";
import vue from "@vitejs/plugin-vue";
import {
  autoComplete,
  Plugin as importToCDN
} from "vite-plugin-cdn-import";

import compressPlugin from 'vite-plugin-compression'
// vant
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {
  VantResolver
} from '@vant/auto-import-resolver';
export default defineConfig({
  server: {
    host:'0.0.0.0',
    hmr: true,
    proxy: {
      "/api": {
        // 请求接口中要替换的标识
        // target: "http://47.108.251.10:9090/", // 代理地址
         target: "http://127.0.0.1:9090/",
        changeOrigin: true, // 是否允许跨域
        secure: true,
        rewrite: (path) => path.replace(/^\/api/, ""), // api标志替换为''
      },
    },
  },
  plugins: [
    vue(),
    compressPlugin({
      ext: ".gz",
      deleteOriginFile: false // 是否删除原始文件
    }),
    // importToCDN({
    //   modules: [
    //     {
    //       name: "vue",
    //       var: "Vue",
    //       path: `https://cdn.bootcdn.net/ajax/libs/vue/3.3.4/vue.global.prod.js`,
    //     },
    //     {
    //       name: "vue-demi",
    //       var: "VueDemi",
    //       path: `https://cdn.staticfile.net/vue-demi/0.13.11/index.iife.js`,
    //     },
    //     {
    //       name: "vue-router",
    //       var: "VueRouter",
    //       path: `https://cdn.staticfile.net/vue-router/4.2.4/vue-router.global.prod.js`,
    //     },
    //     {
    //       name: "element-plus",
    //       var: "ElementPlus",
    //       path: "https://cdn.staticfile.net/element-plus/2.3.12/index.full.min.js",
    //     },
    //     {
    //       name: "avue",
    //       var: "Avue",
    //       path: "https://cdn.jsdelivr.net/npm/@smallwei/avue@3.2.19/lib/avue.min.js",
    //     },
    //   ],
    // }),
    // vant
    AutoImport({
      resolvers: [VantResolver()],
    }),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
});